package com.william.jdbcplus.boot.test.util;

import com.william.jdbcplus.boot.test.constant.GlobalConst;
import com.william.jdbcplus.core.dialect.ddl.DDLUtil;
import lombok.extern.slf4j.Slf4j;

import javax.sql.DataSource;
import java.util.List;

@Slf4j
public class DbOptUtil {
    public static void main(String[] args) {
        DataSource mysqlDatasource = DsUtil.getMysql();
        DataSource oracleDatasource = DsUtil.getOracle();
        DataSource sqlserverDatasource = DsUtil.getSqlServer();

        long beginTime = 0;
        long endTime = 0;
        long consumeTime = 0;
        for (int i = 0; i < 1; i++) {
            // 1、开始时间
            beginTime = System.currentTimeMillis();
            List<String> oracleList = DDLUtil.checkDatabase(GlobalConst.scanPackage, oracleDatasource);
            List<String> oracleSql = DDLUtil.updateDatabaseSqlList(GlobalConst.scanPackage, oracleDatasource);

            // 1、结束时间
            endTime = System.currentTimeMillis();
            // 3、消耗的时间
            consumeTime = endTime - beginTime;
            log.info(String.format(" {oracle consume %d msec}--------------------", consumeTime));

            // 1、开始时间
            beginTime = System.currentTimeMillis();
            List<String> mysqlList = DDLUtil.checkDatabase(GlobalConst.scanPackage, mysqlDatasource);
            List<String> mysqlSql = DDLUtil.updateDatabaseSqlList(GlobalConst.scanPackage, mysqlDatasource);

            // 1、结束时间
            endTime = System.currentTimeMillis();
            // 3、消耗的时间
            consumeTime = endTime - beginTime;
            log.info(String.format(" {mysql consume %d msec}--------------------", consumeTime));

            // 1、开始时间
            beginTime = System.currentTimeMillis();
            List<String> sqlserverList = DDLUtil.checkDatabase(GlobalConst.scanPackage, sqlserverDatasource);
            List<String> sqlserverSql = DDLUtil.updateDatabaseSqlList(GlobalConst.scanPackage, sqlserverDatasource);

            // 1、结束时间
            endTime = System.currentTimeMillis();
            // 3、消耗的时间
            consumeTime = endTime - beginTime;
            log.info(String.format(" {sqlserver consume %d msec}--------------------", consumeTime));

            System.out.println("----------------------oracle----------------------");
            oracleList.stream().forEach(e -> System.out.println(e));
            oracleSql.stream().forEach(e -> System.out.println(e));


            System.out.println("----------------------mysql----------------------");
            mysqlList.stream().forEach(e -> System.out.println(e));
            mysqlSql.stream().forEach(e -> System.out.println(e));


            System.out.println("----------------------sqlserver----------------------");
            sqlserverList.stream().forEach(e -> System.out.println(e));
            sqlserverSql.stream().forEach(e -> System.out.println(e));

            DDLUtil.updateDatabase(GlobalConst.scanPackage, oracleDatasource);
            DDLUtil.updateDatabase(GlobalConst.scanPackage, mysqlDatasource);
            DDLUtil.updateDatabase(GlobalConst.scanPackage, sqlserverDatasource);
        }
    }
}
